package com.example.security.config;

import com.example.security.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 在登录的时候，不用进行token的时间延长，因为是没有token会进行报错
     * 在所有请求的时候，都会进行token是否到期
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/**/login")
                .excludePathPatterns("/user/sendCode")
                .excludePathPatterns("/user/code/login")
                .addPathPatterns("/**");
    }
}
